#ifndef lint
char yysccsid[] = "@(#)yaccpar	1.4 (Berkeley) 02/25/90";
#endif
#line 17 "sp.y"
typedef union {
	int ival;
	char cval;
	char *cpval;
} YYSTYPE;
#line 11 "y.tab.c"
#define STATE 257
#define CODE 258
#define TIME 259
#define RANDOM 260
#define TO 261
#define MINUS 262
#define PLUS 263
#define RUNL 264
#define FIRST 265
#define ABORT 266
#define NAME 267
#define STATUS 268
#define ACTION 269
#define ON 270
#define PNUM 271
#define RESTART 272
#define STRING 273
#define CAPS 274
#define NUMBER 275
#define ADDRESS 276
#define YYERRCODE 256
short yylhs[] = {                                        -1,
    0,    0,    5,    5,    5,    6,    6,    7,    8,    8,
   10,   10,   11,   11,   11,   11,   12,   12,   12,   12,
   12,   12,   14,   14,   14,   14,   14,   14,   14,   14,
   14,   14,   14,   14,   17,   17,   16,   16,   16,   16,
   16,   15,   15,   15,   15,   13,   13,   18,   18,   19,
   19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
   19,   19,    3,    3,    4,    4,    9,    9,   20,   20,
   20,    2,    1,    1,    1,
};
short yylen[] = {                                         2,
    4,    2,    0,    3,    2,    6,    5,    2,    1,    2,
    3,    4,    4,    3,    2,    1,    3,    3,    3,    3,
    3,    3,    0,    4,    5,    7,    9,   11,   13,   15,
   17,   19,   21,   23,    0,    1,    0,    2,    2,    4,
    4,    0,    2,    3,    3,    1,    2,    1,    2,    6,
    7,    7,    6,    7,    6,    7,    6,    7,    6,    7,
    2,    4,    1,    1,    1,    1,    4,    3,    0,    1,
    2,    1,    1,    1,    1,
};
short yydefred[] = {                                      0,
    0,    0,   74,   73,   75,    0,   72,    0,    2,    0,
    0,    0,    0,    5,    1,    0,    0,    4,    8,    0,
    0,    0,    9,    0,    0,    0,    7,    0,   10,    0,
    0,    0,    0,    0,    0,   36,   11,    0,    0,    0,
    0,    0,    0,    0,   48,    0,    0,    6,   12,    0,
    0,    0,    0,    0,    0,   43,    0,    0,    0,    0,
    0,    0,    0,    0,    0,   49,   70,    0,    0,    0,
    0,    0,    0,    0,   45,   44,   17,   18,   20,   19,
   22,   21,    0,   71,    0,    0,   40,   41,   62,   66,
   65,    0,    0,   24,    0,    0,    0,    0,    0,    0,
    0,   25,    0,   63,   64,   50,   53,   55,   57,   59,
    0,    0,    0,    0,    0,    0,    0,   51,   52,   54,
   56,   58,   60,   26,    0,    0,   27,    0,    0,   28,
    0,    0,   29,    0,    0,   30,    0,    0,   31,    0,
    0,   32,    0,    0,   33,    0,    0,   34,
};
short yydgoto[] = {                                       2,
  104,  105,  106,   93,   11,    9,   17,   22,   28,   23,
   37,   38,   39,   40,   41,   42,   43,   44,   45,   68,
};
short yysindex[] = {                                   -265,
 -218, -263,    0,    0,    0, -251,    0,  -84,    0,  -57,
 -263, -227, -263,    0,    0, -218, -246,    0,    0, -263,
   12, -120,    0,   22,  -62,  -56,    0,  -61,    0,  -62,
 -218, -218, -218, -263, -139,    0,    0, -168, -168, -159,
 -187, -236, -263, -168,    0, -263,   36,    0,    0,  -55,
 -186, -157, -167, -218, -218,    0, -168, -168, -229, -142,
 -229, -160, -142, -160,   76,    0,    0, -263, -263, -168,
 -168, -218, -218, -155,    0,    0,    0,    0,    0,    0,
    0,    0,  -41,    0, -263, -168,    0,    0,    0,    0,
    0,   28, -218,    0,    6, -148, -148, -148, -148, -148,
   16,    0, -263,    0,    0,    0,    0,    0,    0,    0,
 -148, -148, -148, -148, -148, -148,    8,    0,    0,    0,
    0,    0,    0,    0, -263,   40,    0, -263,  134,    0,
 -263,  138,    0, -263,  143,    0, -263,  147,    0, -263,
  149,    0, -263,  159,    0, -263,   88,    0,
};
short yyrindex[] = {                                      0,
    0,    0,    0,    0,    0, -133,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0, -132,    0,    0,    0,    0, -132,
    0,    0,    0,    0,    0,    0,    0,    0, -118, -130,
 -248, -248,    0, -116,    0,   29,    0,    0,    0, -132,
 -131,  -88, -122,    0,    0,    0, -107, -105, -130,  -94,
 -130, -248,  -94, -248,    0,    0,    0,   31,   29,    0,
 -103,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,   44, -101,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,
};
short yygindex[] = {                                      0,
   13,   49,   -1,    0,    0,  160,    0,    0,    0,  172,
  171,  158,  -34,  -30,  -25,    2,    0,  -31,  -21,  141,
};
#define YYTABLESIZE 232
short yytable[] = {                                      94,
   13,   46,   61,   57,   27,    1,   16,   58,   46,    7,
   61,   63,   23,    6,   59,   71,   64,   15,   20,   47,
   10,   14,   66,   13,   35,   58,    7,   35,   19,   32,
   33,   80,   36,   82,   78,   86,   66,   81,   12,   58,
   16,   60,   62,   50,   51,   52,  102,   56,  124,  103,
    8,  125,  116,  112,   58,    3,    4,    5,   14,    8,
   77,   18,   79,   48,  100,   21,   75,   76,   24,   25,
   21,   32,   33,   72,   47,  114,  111,  113,  115,   30,
  127,   36,   53,  128,   87,   88,   92,   98,   96,   97,
   99,   65,   34,   69,   67,  107,  108,  109,  110,   32,
   33,   73,   74,   89,   35,  101,   90,   91,   36,  118,
  119,  120,  121,  122,  123,   83,   84,   67,    3,    4,
    5,   35,   54,   55,    7,    3,    4,    5,  148,   38,
   37,   95,   38,   84,    3,    4,    5,   38,   61,    3,
   35,   38,   61,   61,   20,   26,   16,   16,   46,   46,
   61,  117,    7,   69,   16,   68,   46,   15,   15,   47,
   47,   14,   14,   13,   13,   15,   42,   47,   67,   14,
   15,   13,   39,  126,  130,   39,  129,  131,  133,  132,
   39,  134,  135,  136,   39,  138,  137,  139,  141,  142,
  140,  144,  143,   29,  147,   31,   32,   33,   34,  145,
   49,   35,  146,   32,   33,   34,   36,   70,   35,   85,
    0,    0,    0,   36,    0,    7,    7,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    7,
};
short yycheck[] = {                                      41,
   58,   58,  125,   38,  125,  271,  125,   39,  125,  273,
   41,   42,  261,    1,   40,   50,   42,  125,  265,  125,
  272,  125,   44,  125,  273,   57,  273,  264,   16,  259,
  260,   62,  269,   64,   60,   70,   58,   63,  123,   71,
  268,   40,   41,   31,   32,   33,   41,   35,   41,   44,
    2,   44,   37,   38,   86,  274,  275,  276,   10,   11,
   59,   13,   61,  125,   37,   17,   54,   55,   20,   58,
   22,  259,  260,  260,   26,   60,   61,   62,   63,   58,
   41,  269,   34,   44,   72,   73,   74,   60,   61,   62,
   63,   43,  261,   58,   46,   97,   98,   99,  100,  259,
  260,  259,  270,  259,  264,   93,  262,  263,  269,  111,
  112,  113,  114,  115,  116,   40,   68,   69,  274,  275,
  276,  264,  262,  263,  273,  274,  275,  276,   41,  261,
  261,   83,  264,   85,  274,  275,  276,  269,  261,  273,
  273,  273,  265,  266,  265,  266,  265,  266,  265,  266,
  273,  103,  273,  125,  273,  125,  273,  265,  266,  265,
  266,  265,  266,  265,  266,  273,  261,  273,  125,  273,
   11,  273,  261,  125,   41,  264,  128,   44,   41,  131,
  269,   44,  134,   41,  273,  137,   44,   41,  140,   41,
   44,  143,   44,   22,  146,  258,  259,  260,  261,   41,
   30,  264,   44,  259,  260,  261,  269,   50,  264,   69,
   -1,   -1,   -1,  269,   -1,  273,  273,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,  273,
};
#define YYFINAL 2
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 276
#if YYDEBUG
char *yyname[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,"'%'","'&'",0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,
"'<'","'='","'>'","'?'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'{'",0,"'}'",0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,"STATE","CODE","TIME","RANDOM","TO","MINUS","PLUS","RUNL",
"FIRST","ABORT","NAME","STATUS","ACTION","ON","PNUM","RESTART","STRING","CAPS",
"NUMBER","ADDRESS",
};
char *yyrule[] = {
"$accept : statelist",
"statelist : PNUM newnum restart all",
"statelist : statelist all",
"restart :",
"restart : RESTART ':' newstring",
"restart : RESTART newstring",
"all : newstring '{' status states abort '}'",
"all : newstring '{' status states '}'",
"status : STATUS newnum",
"states : shortstate",
"states : states shortstate",
"shortstate : newstring ':' rest",
"shortstate : FIRST newstring ':' rest",
"rest : CODE newnum ta ahead",
"rest : CODE newnum ahead",
"rest : ta ahead",
"rest : ahead",
"ta : action runl time",
"ta : action time runl",
"ta : runl time action",
"ta : runl action time",
"ta : time runl action",
"ta : time action runl",
"action :",
"action : lact newstring '(' ')'",
"action : lact newstring '(' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ')'",
"action : lact newstring '(' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ',' newstring ')'",
"lact :",
"lact : ACTION",
"time :",
"time : TIME newnum",
"time : RANDOM newnum",
"time : TIME newnum RANDOM newnum",
"time : RANDOM newnum TIME newnum",
"runl :",
"runl : RUNL newnum",
"runl : RUNL PLUS newnum",
"runl : RUNL MINUS newnum",
"ahead : esc",
"ahead : ahead esc",
"esc : escape",
"esc : esc escape",
"escape : TO newstring ON newnum '=' address",
"escape : TO newstring ON sign newnum '=' address",
"escape : TO newstring ON sign newnum '&' address",
"escape : TO newstring ON newnum '>' address",
"escape : TO newstring ON sign newnum '>' address",
"escape : TO newstring ON newnum '<' address",
"escape : TO newstring ON sign newnum '<' address",
"escape : TO newstring ON newnum '?' address",
"escape : TO newstring ON sign newnum '?' address",
"escape : TO newstring ON newnum '%' address",
"escape : TO newstring ON sign newnum '%' address",
"escape : TO newstring",
"escape : TO newstring ON TIME",
"address : newnum",
"address : newstring",
"sign : PLUS",
"sign : MINUS",
"abort : ABORT newstring ':' ab1",
"abort : ABORT ':' ab1",
"ab1 :",
"ab1 : newstring",
"ab1 : ab1 newstring",
"newstring : STRING",
"newnum : NUMBER",
"newnum : CAPS",
"newnum : ADDRESS",
};
#endif
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#ifndef YYSTACKSIZE
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 300
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
#define yystacksize YYSTACKSIZE
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#line 519 "sp.y"
#include <stdio.h>
#include "lex.yy.c"
#include <ctype.h>
#include "sp.h"

/* 
 * Commonly used strings.
 */
char *time = {"TIME"};
char *bitoff = {"BITOFF"};
char *biton = {"BITON"};
char *function = {"FUNC"};
char *equal = {"EQUAL"};
char *less = {"LESSOR"};
char *greater = {"GREATER"};
char *question = {"QUERY"};
char *zero = {"0"};
char *one = {"1"};
char *two = {"2"};
char *three = {"3"};

struct names {
	char *sn;	/* state name */
	char *sc;	/* ecode */
	char *sa,*sa1,*sa2,*sa3,*sa4,*sa5,*sa6,*sa7,*sa8,*sa9,*sa10;    /* action and args */
	char *sl;	/* running line flag */
	char *sz;	/* running line value */
	char *st,*sr;	/* preset time, random time */
	struct escp {	/* escapes */
		char *se,*sf,*sad,*sm;
	} es[MAXESC];
	struct names *nptr;
};
struct names list[MAXSTATE] = {0};  /* list of states */
struct names *sptr = list;	/* pointer to current state yacc is processing */
char buffer[MAXLEXBUF] = {0};	/* buffer for lex */
char *lptr = buffer - 1;	/* pointer to null term of last string */
char *begbuf[MAXCHAIN] = {0};	/* pointers to start (FIRST) state of each
				   chain */
char **begstack = begbuf;
char *names[MAXCHAIN] = {0};	/* names of chains */
char **pnames = names;
char *stat[MAXCHAIN] = {0};	/* status of chains (on or off) at init time */
char **pstat = stat;
char *ablist[MAXCHAIN] = {0};	/* aborts of each chain; term by null ptr */
int abcount = 0;		/* number of aborts */
char ab = 'a';
char *fnlist[MAXCHAIN] = {0};	/* restart function names */
char **fnptr = fnlist;
char *pnum = {0};		/* paradigm number */
int i = {0};
int index = {0};
int chain_cnt = {0};		/* total number of chains */
extern FILE *outfd;
int first_seen= 0;

/* 
 * Put out the required #includes.
 */
void
includes(void)
{
/* modified by Long,3-23-07, follow jig's CHANGES file */
	fprintf(stdout,"#include <stdio.h>\n");
	fprintf(stdout,"#include <sys/types.h>\n");
   fprintf(stdout,"#include \"../hdr/rexHdr.h\"\n");
/*
	fprintf(stdout,"#include \"../hdr/sys.h\"\n");
	fprintf(stdout,"#include \"../hdr/cnf.h\"\n");
	fprintf(stdout,"#include \"../hdr/proc.h\"\n");
	fprintf(stdout,"#include \"../hdr/cdsp.h\"\n");
	fprintf(stdout,"#include \"../hdr/idsp.h\"\n");
	fprintf(stdout,"#include \"../hdr/buf.h\"\n");
	fprintf(stdout,"#include \"../hdr/menu.h\"\n");
	fprintf(stdout,"#include \"../hdr/state.h\"\n");
	fprintf(stdout,"#include \"../hdr/ecode.h\"\n");
	fprintf(stdout,"#include \"../hdr/device.h\"\n");
	fprintf(stdout,"#include \"../hdr/int.h\"\n");
*/
 	fprintf(stdout,"\n\n");
}

/* 
 * Put out the states.
 */
void
states_names(void)
{
	register struct names *fptr;
	register struct escp *eptr;
	register int i;

	for (fptr = list; fptr < sptr; fptr++) {
		fprintf(stdout,"STATE s%s = {\n",fptr->sn);
		if(fptr->sc[0] == '&') fprintf(stdout,"\t{\"%s\"},%s,%s\n",fptr->sn,zero,fptr->sc);
		else fprintf(stdout,"\t{\"%s\"},%s,%s\n",fptr->sn,fptr->sc,zero);
		fprintf(stdout,"\t,%s,%s\n",fptr->sz,fptr->sl);
		fprintf(stdout,"\t,{%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s}\n",
				fptr->sa,fptr->sa1,fptr->sa2,fptr->sa3,fptr->sa4,fptr->sa5,
				fptr->sa6,fptr->sa7, fptr->sa8, fptr->sa9, fptr->sa10);
		fprintf(stdout,"\t,%s,%s\n",fptr->st,fptr->sr);

		eptr = fptr->es;
		for (i = 0; i < MAXESC; i++) {
			if(i == 0) fprintf(stdout, "\t,{\n");
			if (*eptr->se == '0') {
				fprintf(stdout,"\t{0,0,%s,%s,",eptr->se,eptr->sf);
				fprintf(stdout,"%s,%s}",eptr->sad,eptr->sm);
			}
			else {
				fprintf(stdout,"\t{0,0,&s%s,%s,",eptr->se,eptr->sf);
				if (islower(*eptr->sad))
					fprintf(stdout,"&%s,%s}",eptr->sad,eptr->sm);
				else fprintf(stdout,"%s,%s}",eptr->sad,eptr->sm);
			}
			if(i != MAXESC-1) fprintf(stdout, ",\n");
			else fprintf(stdout, "\n\t}\n};\n");
			eptr++;
		}
	}
	fprintf(stdout,"\n\n\n");
}

/* 
 * Put out all needed external declarations.
 */
void
globals_names(void)
{
	register int i;
	register struct names *fptr;
	register struct escp *eptr;

	printf("\n\n");
	for (fptr = list; fptr < sptr; fptr++) {
		if (islower(*fptr->sa)) {
			fprintf(stdout,"extern int %s();\n",fptr->sa);
		}
		eptr = fptr->es;
		for (i = 0; i < MAXESC; i++) {
 		  if(islower(*eptr->sad)) {
		    if(eptr->sf == function) {
		      fprintf(stdout,"extern int %s();\n",eptr->sad);
		    } else {
		      char *cp;

		      cp= eptr->sad;

		      /*
		       * Don't output extern declaration if variable is
		       * a struct or array.  Let user do it explicitly.
		       */
		      while(*cp != '\0') {
			if(*cp == '[' || *cp == '.') break;
			cp++;
		      }
		      if(*cp == '\0')
	      		 fprintf(stdout,"extern int %s;\n",eptr->sad);
		    }
		  }
		  eptr++;
		}
	}
	fprintf(stdout,"\n\n\n");

	for (fptr = list; fptr < sptr; fptr++) {
		fprintf(stdout,"STATE s%s;\n",fptr->sn);
	}
	fprintf(stdout,"\n\n\n");
	fprintf(stdout,"STATE *snames[] = {\n");
	for (fptr = list; fptr < sptr; fptr++) {
		fprintf(stdout,"&s%s,\n",fptr->sn);
	}
	fprintf(stdout,"0};\n\n");
}

/*
 * Zero state tables.
 */
void
ilist(void)
{
	register struct names *kptr;
	register int i;

	for (kptr = list; kptr < &list[MAXSTATE]; kptr++) {
			kptr->sn = zero;
			kptr->sc = zero;
			kptr->sl = zero;
			kptr->sz = zero;
			kptr->sa = zero;
			kptr->sa1 = zero;
			kptr->sa2 = zero;
			kptr->sa3 = zero;
			kptr->sa4 = zero;
			kptr->sa5 = zero;
			kptr->sa6 = zero;
			kptr->sa7 = zero;
			kptr->sa8 = zero;
			kptr->sa9 = zero;
			kptr->sa10 = zero;
			kptr->st = zero;
			kptr->sr = zero;
			for (i = 0; i < MAXESC; i++) {
				kptr->es[i].sf = zero;
				kptr->es[i].sad = zero;
				kptr->es[i].se = zero;
				kptr->es[i].sm = zero;
			}
	}
}

/*
 * Get out the structures which are used by the state processor.
 */
void
inittable(void)
{
	register char **fptr;
	int i;

	fprintf(stdout,"int sf_init();\n\n");
	fprintf(stdout,"STATE sps_state;\n\n");
	fprintf(stdout,"AWAKE init_state[] = {\n");
	fprintf(stdout,"\t{0,ON,ON,&sps_state,&sps_state,0,(STATE *)&init_state[1],0,\n\
			&sps_state.escape}\n");
	fprintf(stdout,"\t,{0,0,0,0,0,0,0,0,&sps_state.escape[1]}\n};\n");

	fprintf(stdout,"STATE sps_state = {\n");
	fprintf(stdout, "\t{\"spec\"},1,0\n\t,1,0\n");
	fprintf(stdout, "\t,{sf_init,%s,0,0,0,0,0,0,0,0,0}\n", pnum);
	fprintf(stdout,"\t,0,0\n\t,{\n\t{0,init_state,&sps_state,TIME,0,0}\n");
	fprintf(stdout,"\t,{0,0,0,0,0,0}\n\t}\n};\n");

	fprintf(stdout,"AWAKE nowstate[] = {\n\t");
	for (i = 0; i < chain_cnt; i++) {
		fprintf(stdout,"{0,%s,%s,&s%s,&s%s,abort%c,0,0,0}\n\t,",stat[i],stat[i],begbuf[i],
			begbuf[i],'a' + i);
	}

	fprintf(stdout,"{0,0,0,0,0,0,0,0,0}");
	fprintf(stdout,"\n};\n\n");


	/* the following is the kludge for init routines to be called */
	for (fptr = fnlist; *fptr; fptr++) {
		fprintf(stdout,"void %s();\n",*fptr);
	}

	fprintf(stdout,"int (*init_list[])() = {\n");
	for (fptr = fnlist; *fptr; fptr++) {
		fprintf(stdout,"%s,\n",*fptr);
	}

	fprintf(stdout,"0};\n");
	fflush(stdout);
}

/*
 * Put out the abort lists for the different chains.
 */
void
aborts(void)
{
	int i;
	register char **fptr;

	fptr = ablist;

	for (i = 0; i < chain_cnt; i++) {
		fprintf(stdout,"STATE *abort%c[] = {\n",ab++);
		for (; *fptr; fptr++) {
			fprintf(stdout,"&s%s,\n",*fptr);
		}

		fprintf(stdout,"0};\n\n");
		fptr++;
	}
}

/*
 * Only error is return line number of error.
 */
void
yyerror(char *s)
{
	extern int lineno;

	fprintf(stderr,"error %s: line %d\n", s, lineno);
}

void
spot(void)
{
	go();		/* set up lex to be in the proper state */
	ilist();
	includes();
	yyparse();
	globals_names();
	usercode();
	states_names();
	aborts();
	inittable();
	varlist();
}

#line 585 "y.tab.c"
#define YYABORT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
    register int yym, yyn, yystate;
#if YYDEBUG
    register char *yys;
    extern char *getenv();

    if (yys = getenv("YYDEBUG"))
    {
        yyn = *yys;
        if (yyn >= '0' && yyn <= '9')
            yydebug = yyn - '0';
    }
#endif

    yynerrs = 0;
    yyerrflag = 0;
    yychar = (-1);

    yyssp = yyss;
    yyvsp = yyvs;
    *yyssp = yystate = 0;

yyloop:
    if (yyn = yydefred[yystate]) goto yyreduce;
    if (yychar < 0)
    {
        if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("yydebug: state %d, reading %d (%s)\n", yystate,
                    yychar, yys);
        }
#endif
    }
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
#if YYDEBUG
        if (yydebug)
            printf("yydebug: state %d, shifting to state %d\n",
                    yystate, yytable[yyn]);
#endif
        if (yyssp >= yyss + yystacksize - 1)
        {
            goto yyoverflow;
        }
        *++yyssp = yystate = yytable[yyn];
        *++yyvsp = yylval;
        yychar = (-1);
        if (yyerrflag > 0)  --yyerrflag;
        goto yyloop;
    }
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
        yyn = yytable[yyn];
        goto yyreduce;
    }
    if (yyerrflag) goto yyinrecovery;
#ifdef lint
    goto yynewerror;
#endif
yynewerror:
    yyerror("syntax error");
#ifdef lint
    goto yyerrlab;
#endif
yyerrlab:
    ++yynerrs;
yyinrecovery:
    if (yyerrflag < 3)
    {
        yyerrflag = 3;
        for (;;)
        {
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
#if YYDEBUG
                if (yydebug)
                    printf("yydebug: state %d, error recovery shifting\
 to state %d\n", *yyssp, yytable[yyn]);
#endif
                if (yyssp >= yyss + yystacksize - 1)
                {
                    goto yyoverflow;
                }
                *++yyssp = yystate = yytable[yyn];
                *++yyvsp = yylval;
                goto yyloop;
            }
            else
            {
#if YYDEBUG
                if (yydebug)
                    printf("yydebug: error recovery discarding state %d\n",
                            *yyssp);
#endif
                if (yyssp <= yyss) goto yyabort;
                --yyssp;
                --yyvsp;
            }
        }
    }
    else
    {
        if (yychar == 0) goto yyabort;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("yydebug: state %d, error recovery discards token %d (%s)\n",
                    yystate, yychar, yys);
        }
#endif
        yychar = (-1);
        goto yyloop;
    }
yyreduce:
#if YYDEBUG
    if (yydebug)
        printf("yydebug: state %d, reducing by rule %d (%s)\n",
                yystate, yyn, yyrule[yyn]);
#endif
    yym = yylen[yyn];
    yyval = yyvsp[1-yym];
    switch (yyn)
    {
case 1:
#line 37 "sp.y"
{
				pnum = yyvsp[-2].cpval ;
			}
break;
case 4:
#line 45 "sp.y"
{
				*fnptr++ = yyvsp[0].cpval ;
			}
break;
case 5:
#line 49 "sp.y"
{
				*fnptr++ = yyvsp[0].cpval ;
			}
break;
case 6:
#line 55 "sp.y"
{
				if(!first_seen) {
				    fprintf(stderr,
				      "CHAIN '%s' has no 'begin' state\n",
					    yyvsp[-5].cpval );
				    exit(1);
				}
				*pnames++ = yyvsp[-5].cpval ;
				chain_cnt++;
				first_seen= 0;
				abcount++;
			}
break;
case 7:
#line 68 "sp.y"
{
				if(!first_seen) {
				  fprintf(stderr,
				    "CHAIN '%s' has no 'begin' state\n",
					    yyvsp[-4].cpval );
				  exit(1);
				}
				*pnames++ = yyvsp[-4].cpval ;
				chain_cnt++;
				first_seen= 0;
				abcount++;
			}
break;
case 8:
#line 83 "sp.y"
{
			*pstat++ = yyvsp[0].cpval ;
		}
break;
case 9:
#line 89 "sp.y"
{
				sptr++;
				index = 0;
			}
break;
case 10:
#line 94 "sp.y"
{
				sptr++;
				index = 0;
			}
break;
case 11:
#line 101 "sp.y"
{
				sptr->sn = yyvsp[-2].cpval ;
				if (index >= MAXESC) {
					fprintf(stderr,
						"STATE %s: too many escapes\n",
						sptr->sn);
					exit(1);
				}
			}
break;
case 12:
#line 111 "sp.y"
{
				if(strncmp(zero, sptr->sa, sizeof(zero)) !=
				   0) {
				   fprintf(stderr,
				     "STATE '%s': 'begin' state cannot contain an action\n",
					   yyvsp[-2].cpval );
			           exit(1);
				}
				if(first_seen) {
				    fprintf(stderr,
			"STATE '%s': only one 'begin' state per chain allowed\n",
					yyvsp[-2].cpval );
				    exit(1);
				} else first_seen= 1;
				*begstack++ = yyvsp[-2].cpval ;
				sptr->sn = yyvsp[-2].cpval ;
				if (index >= MAXESC) {
					fprintf(stderr,
						"STATE %s: too many escapes\n",
						sptr->sn);
					exit(1);
				}
			}
break;
case 13:
#line 137 "sp.y"
{
				sptr->sc = yyvsp[-2].cpval ;
			}
break;
case 14:
#line 141 "sp.y"
{
				sptr->sc = yyvsp[-1].cpval ;
			}
break;
case 24:
#line 158 "sp.y"
{
			sptr->sa = yyvsp[-2].cpval ;
		}
break;
case 25:
#line 162 "sp.y"
{
				sptr->sa = yyvsp[-3].cpval ;
				sptr->sa1 = yyvsp[-1].cpval ;
			}
break;
case 26:
#line 167 "sp.y"
{
				sptr->sa = yyvsp[-5].cpval ;
				sptr->sa1 = yyvsp[-3].cpval ;
				sptr->sa2 = yyvsp[-1].cpval ;
			}
break;
case 27:
#line 173 "sp.y"
{
				sptr->sa = yyvsp[-7].cpval ;
				sptr->sa1 = yyvsp[-5].cpval ;
				sptr->sa2 = yyvsp[-3].cpval ;
				sptr->sa3 = yyvsp[-1].cpval ;
			}
break;
case 28:
#line 181 "sp.y"
{
				sptr->sa = yyvsp[-9].cpval ;
				sptr->sa1 = yyvsp[-7].cpval ;
				sptr->sa2 = yyvsp[-5].cpval ;
				sptr->sa3 = yyvsp[-3].cpval ;
				sptr->sa4 = yyvsp[-1].cpval ;
			}
break;
case 29:
#line 190 "sp.y"
{
				sptr->sa = yyvsp[-11].cpval ;
				sptr->sa1 = yyvsp[-9].cpval ;
				sptr->sa2 = yyvsp[-7].cpval ;
				sptr->sa3 = yyvsp[-5].cpval ;
				sptr->sa4 = yyvsp[-3].cpval ;
				sptr->sa5 = yyvsp[-1].cpval ;
			}
break;
case 30:
#line 200 "sp.y"
{
				sptr->sa = yyvsp[-13].cpval ;
				sptr->sa1 = yyvsp[-11].cpval ;
				sptr->sa2 = yyvsp[-9].cpval ;
				sptr->sa3 = yyvsp[-7].cpval ;
				sptr->sa4 = yyvsp[-5].cpval ;
				sptr->sa5 = yyvsp[-3].cpval ;
				sptr->sa6 = yyvsp[-1].cpval ;
			}
break;
case 31:
#line 211 "sp.y"
{
				sptr->sa = yyvsp[-15].cpval ;
				sptr->sa1 = yyvsp[-13].cpval ;
				sptr->sa2 = yyvsp[-11].cpval ;
				sptr->sa3 = yyvsp[-9].cpval ;
				sptr->sa4 = yyvsp[-7].cpval ;
				sptr->sa5 = yyvsp[-5].cpval ;
				sptr->sa6 = yyvsp[-3].cpval ;
				sptr->sa7 = yyvsp[-1].cpval ;
			}
break;
case 32:
#line 224 "sp.y"
{
				sptr->sa = yyvsp[-17].cpval ;
				sptr->sa1 = yyvsp[-15].cpval ;
				sptr->sa2 = yyvsp[-13].cpval ;
				sptr->sa3 = yyvsp[-11].cpval ;
				sptr->sa4 = yyvsp[-9].cpval ;
				sptr->sa5 = yyvsp[-7].cpval ;
				sptr->sa6 = yyvsp[-5].cpval ;
				sptr->sa7 = yyvsp[-3].cpval ;
				sptr->sa8 = yyvsp[-1].cpval ;
			}
break;
case 33:
#line 238 "sp.y"
{
				sptr->sa = yyvsp[-19].cpval ;
				sptr->sa1 = yyvsp[-17].cpval ;
				sptr->sa2 = yyvsp[-15].cpval ;
				sptr->sa3 = yyvsp[-13].cpval ;
				sptr->sa4 = yyvsp[-11].cpval ;
				sptr->sa5 = yyvsp[-9].cpval ;
				sptr->sa6 = yyvsp[-7].cpval ;
				sptr->sa7 = yyvsp[-5].cpval ;
				sptr->sa8 = yyvsp[-3].cpval ;
				sptr->sa9 = yyvsp[-1].cpval ;
			}
break;
case 34:
#line 253 "sp.y"
{
				sptr->sa = yyvsp[-21].cpval ;
				sptr->sa1 = yyvsp[-19].cpval ;
				sptr->sa2 = yyvsp[-17].cpval ;
				sptr->sa3 = yyvsp[-15].cpval ;
				sptr->sa4 = yyvsp[-13].cpval ;
				sptr->sa5 = yyvsp[-11].cpval ;
				sptr->sa6 = yyvsp[-9].cpval ;
				sptr->sa7 = yyvsp[-7].cpval ;
				sptr->sa8 = yyvsp[-5].cpval ;
				sptr->sa9 = yyvsp[-3].cpval ;
				sptr->sa10 = yyvsp[-1].cpval ;
			}
break;
case 38:
#line 272 "sp.y"
{
				sptr->st = yyvsp[0].cpval ;
			}
break;
case 39:
#line 276 "sp.y"
{
				sptr->sr = yyvsp[0].cpval ;
			}
break;
case 40:
#line 280 "sp.y"
{
				sptr->st = yyvsp[-2].cpval ;
				sptr->sr = yyvsp[0].cpval ;
			}
break;
case 41:
#line 285 "sp.y"
{
				sptr->sr = yyvsp[-2].cpval ;
				sptr->st = yyvsp[0].cpval ;
			}
break;
case 43:
#line 293 "sp.y"
{
				sptr->sz = one;
				sptr->sl = yyvsp[0].cpval ;
			}
break;
case 44:
#line 298 "sp.y"
{
				sptr->sz = two;
				sptr->sl = yyvsp[0].cpval ;
			}
break;
case 45:
#line 303 "sp.y"
{
				sptr->sz = three;
				sptr->sl = yyvsp[0].cpval ;
			}
break;
case 46:
#line 310 "sp.y"
{
			}
break;
case 47:
#line 313 "sp.y"
{
			}
break;
case 49:
#line 319 "sp.y"
{
			}
break;
case 50:
#line 324 "sp.y"
{
			sptr->es[index].se = yyvsp[-4].cpval ;
			sptr->es[index].sf = equal;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 51:
#line 332 "sp.y"
{
			char *tmp;

			/* this will work because a leading ' ' exists */
			if (yyvsp[-3].cpval  == bitoff) {
				yyvsp[-2].cpval  = yyvsp[-2].cpval  - 1;
				tmp = yyvsp[-2].cpval ;
				*tmp = '-';
			}
			sptr->es[index].se = yyvsp[-5].cpval ;
			sptr->es[index].sf = equal;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 52:
#line 348 "sp.y"
{
			sptr->es[index].se = yyvsp[-5].cpval ;
			sptr->es[index].sf = yyvsp[-3].cpval ;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 53:
#line 356 "sp.y"
{
			sptr->es[index].se = yyvsp[-4].cpval ;
			sptr->es[index].sf = greater;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 54:
#line 364 "sp.y"
{
			char *tmp;

			/* this will work because a leading ' ' exists */
			if (yyvsp[-3].cpval  == bitoff) {
				yyvsp[-2].cpval  = yyvsp[-2].cpval  - 1;
				tmp = yyvsp[-2].cpval ;
				*tmp = '-';
			}
			sptr->es[index].se = yyvsp[-5].cpval ;
			sptr->es[index].sf = greater;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 55:
#line 380 "sp.y"
{
			sptr->es[index].se = yyvsp[-4].cpval ;
			sptr->es[index].sf = less;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 56:
#line 388 "sp.y"
{
			char *tmp;

			/* this will work because a leading ' ' exists */
			if (yyvsp[-3].cpval  == bitoff) {
				yyvsp[-2].cpval  = yyvsp[-2].cpval  - 1;
				tmp = yyvsp[-2].cpval ;
				*tmp = '-';
			}
			sptr->es[index].se = yyvsp[-5].cpval ;
			sptr->es[index].sf = less;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 57:
#line 404 "sp.y"
{
			sptr->es[index].se = yyvsp[-4].cpval ;
			sptr->es[index].sf = question;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 58:
#line 412 "sp.y"
{
			char *tmp;

			/* this will work because a leading ' ' exists */
			if (yyvsp[-3].cpval  == bitoff) {
				yyvsp[-2].cpval  = yyvsp[-2].cpval  - 1;
				tmp = yyvsp[-2].cpval ;
				*tmp = '-';
			}
			sptr->es[index].se = yyvsp[-5].cpval ;
			sptr->es[index].sf = question;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 59:
#line 428 "sp.y"
{
			sptr->es[index].se = yyvsp[-4].cpval ;
			sptr->es[index].sf = function;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 60:
#line 436 "sp.y"
{
			char *tmp;

			/* this will work because a leading ' ' exists */
			if (yyvsp[-3].cpval  == bitoff) {
				yyvsp[-2].cpval  = yyvsp[-2].cpval  - 1;
				tmp = yyvsp[-2].cpval ;
				*tmp = '-';
			}
			sptr->es[index].se = yyvsp[-5].cpval ;
			sptr->es[index].sf = function;
			sptr->es[index].sad = yyvsp[0].cpval ;
			sptr->es[index].sm = yyvsp[-2].cpval ;
			index++;
		}
break;
case 61:
#line 452 "sp.y"
{
			sptr->es[index].se = yyvsp[0].cpval ;
			sptr->es[index].sf = time;
			index++;
		}
break;
case 62:
#line 458 "sp.y"
{
			sptr->es[index].se = yyvsp[-2].cpval ;
			sptr->es[index].sf = time;
			index++;
		}
break;
case 63:
#line 465 "sp.y"
{
				yyval.cpval  = yyvsp[0].cpval ;
			}
break;
case 64:
#line 469 "sp.y"
{
				yyval.cpval  = yyvsp[0].cpval ;
			}
break;
case 65:
#line 474 "sp.y"
{
				yyval.cpval  = biton;
			}
break;
case 66:
#line 478 "sp.y"
{
				yyval.cpval  = bitoff;
			}
break;
case 70:
#line 489 "sp.y"
{
				ablist[abcount++] = yyvsp[0].cpval ;
			}
break;
case 71:
#line 493 "sp.y"
{
				ablist[abcount++] = yyvsp[0].cpval ;
			}
break;
case 72:
#line 499 "sp.y"
{
			yyval.cpval  = yyvsp[0].cpval ;
			}
break;
case 73:
#line 505 "sp.y"
{
				yyval.cpval  = yyvsp[0].cpval ;
			}
break;
case 74:
#line 509 "sp.y"
{
				yyval.cpval  = yyvsp[0].cpval ;
			}
break;
case 75:
#line 513 "sp.y"
{
				yyval.cpval  = yyvsp[0].cpval ;
			}
break;
#line 1252 "y.tab.c"
    }
    yyssp -= yym;
    yystate = *yyssp;
    yyvsp -= yym;
    yym = yylhs[yyn];
    if (yystate == 0 && yym == 0)
    {
#ifdef YYDEBUG
        if (yydebug)
            printf("yydebug: after reduction, shifting from state 0 to\
 state %d\n", YYFINAL);
#endif
        yystate = YYFINAL;
        *++yyssp = YYFINAL;
        *++yyvsp = yyval;
        if (yychar < 0)
        {
            if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
            if (yydebug)
            {
                yys = 0;
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
                if (!yys) yys = "illegal-symbol";
                printf("yydebug: state %d, reading %d (%s)\n",
                        YYFINAL, yychar, yys);
            }
#endif
        }
        if (yychar == 0) goto yyaccept;
        goto yyloop;
    }
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn];
    else
        yystate = yydgoto[yym];
#ifdef YYDEBUG
    if (yydebug)
        printf("yydebug: after reduction, shifting from state %d \
to state %d\n", *yyssp, yystate);
#endif
    if (yyssp >= yyss + yystacksize - 1)
    {
        goto yyoverflow;
    }
    *++yyssp = yystate;
    *++yyvsp = yyval;
    goto yyloop;
yyoverflow:
    yyerror("yacc stack overflow");
yyabort:
    return (1);
yyaccept:
    return (0);
}
